<template>
    <div class="page">
        <!-- 用户信息区域 -->
        <div class="user-info">
            <div class="avatar-container">
                <img :src="userStore.userInfo.userPic" class="avatar">
                <span class="username">{{ userStore.userInfo.username }}</span>
            </div>
        </div>

        <!-- 功能列表区域 -->
        <div class="content">
            <div class="menu-list">
                <div class="menu-item" @click="handleEdit">
                    <img src="@/assets/images/mine/updatePassWord.png" />
                    <span> 修改密码</span>
                </div>
                <div class="menu-item" @click="handlePets">
                    <img src="@/assets/images/mine/updateUserInfo.png" />
                    <span> 修改个人信息</span>
                </div>
                <div class="menu-item" @click="handleFavorites">
                    <img src="@/assets/images/mine/UpdateTouxiang.png" />
                    <span> 修改头像</span>
                </div>
                <div class="menu-item" @click="showContactDialog">
                    <img src="@/assets/images/mine/contact.png" />
                    <span> 联系我们</span>
                </div>
                <div class="menu-item" @click="handleLogout">
                    <img src="@/assets/images/mine/log-out.png" />
                    <span> 退出登录</span>
                </div>
            </div>
        </div>
        <TabNav />

        <!-- 联系我们弹窗 -->
        <van-dialog v-model:show="showContact" title="联系我们" :show-cancel-button="false" confirm-button-text="关闭"
            confirm-button-color="#8D9F5E">
            <div class="contact-content">
                <p>客服请联系：</p>
                <p>卓先生</p>
                <p>邮箱：3523118228@qq.com</p>
                <p>QQ：3523118228</p>
            </div>
        </van-dialog>
    </div>
</template>

<script setup>
defineOptions({
    name: 'MineIndex'
})

import TabNav from '@/components/TabNav/TabNav.vue'
import { useUserStore } from "@/stores/user";
import { useRouter } from 'vue-router';
import { ref } from 'vue';

const router = useRouter();
const userStore = useUserStore();
const showContact = ref(false);

const handleEdit = () => {
    router.push('/modifyPassword');
}

const handlePets = () => {
    router.push('/my-pets');
}

const handleFavorites = () => {
    router.push('/favorites');
}

const handleLogout = () => {
    userStore.clearUserInfo();
    router.push('/login');
}

const showContactDialog = () => {
    showContact.value = true;
}
</script>

<style lang="scss" scoped>
.page {
    background: #8D9F5E;
    width: 100%;
    height: 100vh;
    position: relative;

    .user-info {
        padding-top: 40px;
        padding-bottom: 100px;

        .avatar-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 12px;

            .avatar {
                width: 80px;
                height: 80px;
                border-radius: 50%;
                border: 2px solid #fff;
                object-fit: cover;
            }

            .username {
                color: #fff;
                font-size: 20px;
                font-weight: 500;
            }
        }
    }

    .content {
        position: absolute;
        top: 170px;
        width: 100%;
        height: calc(100vh - 170px - 60px);
        background-color: #fff;
        border-radius: 25px 25px 0 0;
        padding: 20px;

        .menu-list {
            padding: 20px 0;

            .menu-item {
                display: flex;
                align-items: center;
                padding: 16px 20px;
                margin-bottom: 10px;
                cursor: pointer;
                border-radius: 12px;
                transition: background-color 0.3s;
                position: relative;

                &:not(:last-child)::after {
                    content: '';
                    position: absolute;
                    bottom: -5px;
                    left: 20px;
                    right: 20px;
                    height: 1px;
                    background: #E5E5E5;
                    border-bottom: 1px dashed #E5E5E5;
                }

                &:hover {
                    background-color: #f5f5f5;
                }

                img {
                    width: 24px;
                    height: 24px;
                    margin-right: 12px;
                }

                span {
                    color: #333;
                    font-size: 16px;
                }
            }
        }
    }
}

.contact-content {
    padding: 20px;
    text-align: center;

    p {
        margin: 10px 0;
        color: #333;
        font-size: 14px;

        &:first-child {
            font-weight: bold;
            margin-bottom: 15px;
        }
    }
}

// 修改弹窗样式
:deep(.van-dialog) {
    border-radius: 12px;
    overflow: hidden;

    .van-dialog__header {
        padding: 15px;
        font-weight: bold;
        color: #333;
    }
}
</style>